﻿#include "EventHandlerUnknownConnection.hpp"
#include "Node/Bridge.pb.h"
#include "BridgeIOServer.hpp"

EventHandlerUnknownConnection::EventHandlerUnknownConnection(BridgeIOServer* pServer)
{
	mpServer = pServer;
	mMessageRouter.registerHandler(
		Bridge::EBridgeNodeRegisterReq,
		[this](Message& msg) {
		onFromBridgeNodeRegisterReq(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeReqSubMainVehicle,
		[this](Message& msg) {
		onFromBridgeReqSubMainVehicle(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::ESensorAnyDataMessage,
		[this](Message& msg) {
		onFromSensorAnyDataMessage(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EMainVehicleAnyDataMessage,
		[this](Message& msg) {
		onFromMainVehicleDataMessage(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::ESensorPhysicalBasedDataConfig,
		[this](Message& msg) {
		onFromBridgeSensorPhysicalBasedDataConfig(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeTimeStepForwardConfirm,
		[this](Message& msg) {
		onFromBridgeTimeStepForwardConfirmDataMessage(msg);
	});

	mMessageRouter.registerHandler(
		Bridge::ESensorObjectbasedDataConfig,
		[this](Message& msg) {
		onFromBridgeSensorObjectbasedDataConfig(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::ESensorOSIDataConfig,
		[this](Message& msg) {
		onFromBridgeSensorOSIDataConfig(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeReqMainVehicleList,
		[this](Message& msg) {
		onFromBridgeMainVehicleInfo(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeReqMainVehicleStatus,
		[this](Message& msg) {
		onFromBridgeMainVehicleStatus(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeMessageFromOut2SimOneWriteReq,
		[this](Message& msg) {
		onFromBridgeMessageFromOut2SimOneWriteReq(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeMessageSimOneOutReadReq,
		[this](Message& msg) {
		onFromBridgeMessageSimOneOutReadReq(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeMessageSimOneOutReadResult,
		[this](Message& msg) {
		onFromBridgeMessageSimOneOutReadResult(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeSimOneAPIReady,
		[this](Message& msg) {
		onFromBridgeMessage(msg);
	});
	mMessageRouter.registerHandler(
		Bridge::EBridgeDataRoute,
		[this](Message& msg) {
		onFromBridgeRoute(msg);
	});
}

EventHandlerUnknownConnection::~EventHandlerUnknownConnection()
{
}

void EventHandlerUnknownConnection::onDisposed()
{
}

void EventHandlerUnknownConnection::onDisconnected()
{
	mpServer->OnDisConnectClient(getSocket());
}

void EventHandlerUnknownConnection::onConnected()
{
}

void EventHandlerUnknownConnection::onMessage(Message& msg)
{
	mMessageRouter.onMessage(msg);
}

void EventHandlerUnknownConnection::onFromBridgeNodeRegisterReq(Message& msg)
{
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeReqSubMainVehicle(Message& msg)
{
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeVehicleBodyState(Message& msg) {

	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeVehicleExtraState(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeVehicleControlState(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeVehicleEventInfo(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeVehicleTrajectoryState(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeTimeStepForwardConfirmDataMessage(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromMainVehicleDataMessage(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeSensorPhysicalBasedDataConfig(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeSensorObjectbasedDataConfig(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeSensorOSIDataConfig(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromSensorAnyDataMessage(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeMainVehicleInfo(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeMainVehicleStatus(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeMessageFromOut2SimOneWriteReq(Message & msg){
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeMessageSimOneOutReadReq(Message & msg)
{
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeMessageSimOneOutReadResult(Message & msg)
{
	mpServer->queueControlCommand(getSocket(), msg);
}
void EventHandlerUnknownConnection::onFromBridgeMessage(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}

void EventHandlerUnknownConnection::onFromBridgeRoute(Message& msg) {
	mpServer->queueControlCommand(getSocket(), msg);
}